def write_file(file, mode, values):
    with open('data/'+file, mode, encoding='utf-8') as f:
        f.write(','.join(values))


def read_file(file, mode):
    with open('data/'+file, mode, encoding='utf-8') as f:
        s = f.read()
        s = s.split(',')
        print('s = ', s, end='\n')


items = ['张三', '李四', '王五', '陈六']
write_file('ggg.csv', 'w', items)
read_file('ggg.csv', 'r')


def write_two_dimensional(file, mode, values):
    with open('data/'+file, mode, encoding='utf-8') as f:
        for v in values:
            f.write(','.join(v) + '\n')


def read_two_dimensional(file, mode):
    data = []
    with open('data/'+file, mode, encoding='utf-8') as f:
        results = f.readlines()
        for v in results:
            if len(v) <= 0:
                continue
            data.append(v.strip().split(','))
        print(data)


items = [
    ['商品名称', '单价', '采购数量'],
    ['水杯', '99', '20'],
    ['盘子', '22', '10']
]
write_two_dimensional('hhh.csv', 'w', items)
read_two_dimensional('hhh.csv', 'r')